import React, { useEffect, useState } from 'react';
import { Modal, Form, Space } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect, history } from 'umi';
import { Button, Row, Col, notification } from 'antd';
import {
    fakeAdminLogHideFlag,
    fakeSetStageHideFlag,
    fakeSetScoreHideFlag,
    fakeSetThirdEventHideFlag,
    fakeSetHideFlag,
    fakeUserAdminActivityLogHideFlag
} from '@/services/systemServices'
const CheckOrderForm = (props) => {
    const { visible = false, onClose, loading, dispatch, handleCallback, } = props;
    const { show = false, detail = {}, type = 'show' } = visible;
    const { id } = detail;

    const [form] = Form.useForm();
    // 确认提交
    const handleUpAudit = () => {
        form.validateFields().then((values) => {
            const { followUp, stage, adminLog, thirdEvent, score, userAdmin } = values
            const requestList = {}
            if (followUp == 1) {
                requestList.followUp = fakeSetHideFlag

            }
            if (stage == 1) {
                requestList.stage = fakeSetStageHideFlag


            }
            if (adminLog == 1) {
                requestList.adminLog = fakeAdminLogHideFlag
            }
            if (thirdEvent == 1) {
                requestList.thirdEvent = fakeSetThirdEventHideFlag
            }
            if (score == 1) {
                requestList.score = fakeSetScoreHideFlag
            }
            if (userAdmin == 1) {
                requestList.userAdmin = fakeUserAdminActivityLogHideFlag
            }
            const labelMessage = {
                followUp: '隐藏跟进信息错误，',
                stage: '隐藏阶段信息错误，',
                adminLog: '隐藏分配日志错误，',
                thirdEvent: '隐藏三方事件错误，',
                followUp: '隐藏得分记录错误，',
                userAdmin: '隐藏员工操作错误，'
            }
            if (Object.values(requestList).length > 0) {
                Promise.all(Object.values(requestList).map(item => {
                    return item({
                        adminId: id,
                        hideFlag: '1',
                        messageNone: true
                    })
                })).then(val => {
                    const message = val.reduce((item, o, index) => {
                        const list = Object.keys(requestList)
                        const { resultCode, resultDesc } = o
                        if (resultCode !== '1') {
                            if (val.length - 1 > index) {
                                return item + labelMessage[list[index]]
                            }
                            else {
                                return item + labelMessage[list[index]]
                            }
                        }
                        return item
                    }, '')
                    if (message) {
                        notification.warning({
                            message: '错误提示',
                            description: message + '请联系管理员',
                        })
                        if (type === 'hide') {
                            onClose()
                            return
                        }
                        dispatch({
                            type: 'system/fakeDisableAdmin',
                            payload: { id: id },
                            callback: (e) => {
                                onClose()
                                handleCallback();
                            },
                        });
                    }
                    else {
                        if (type === 'hide') {
                            onClose()
                            return
                        }
                        dispatch({
                            type: 'system/fakeDisableAdmin',
                            payload: { id: id },
                            callback: (e) => {
                                onClose()
                                handleCallback();
                            },
                        });
                    }
                })
            } else {
                if (type === 'hide') {
                    onClose()
                    return
                }
                dispatch({
                    type: 'system/fakeDisableAdmin',
                    payload: { id: id },
                    callback: (e) => {
                        onClose()
                        handleCallback();
                    },
                });
            }
        });



    };
    useEffect(() => {
        if (!show) {
        } else {

        }
    }, [show])
    const formItems = [
        {
            label: `隐藏跟进信息`,
            name: 'followUp',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },
        {
            label: `隐藏阶段信息`,
            name: 'stage',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },
        {
            label: `隐藏分配日志`,
            name: 'adminLog',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },
        {
            label: `隐藏三方事件`,
            name: 'thirdEvent',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },
        {
            label: `隐藏得分记录`,
            name: 'score',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },

        {
            label: `隐藏员工操作`,
            name: 'userAdmin',
            type: 'radio',
            style: { textAlign: 'left' },
            select: {
                0: '否',
                1: '是'
            },
        },
    ];

    const modalProps = {
        title: '隐藏业务',
        width: 600,
        visible: show,
        maskClosable: true,
        destroyOnClose: true,
        zIndex: 1001,
        confirmLoading: loading,
    };

    return (
        <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
            <Space direction={'vertical'} style={{ display: 'flex', textAlign: 'center', justifyContent: 'center', width: '100%' }}>
                <FormCondition form={form} initialValues={{
                    followUp: '0',
                    stage: '0',
                    thirdEvent: '0',
                    score: '0',
                    adminLog: '0',
                    userAdmin: '0'
                }} formItems={formItems}></FormCondition>
            </Space>

        </Modal >
    );
};

export default connect(({ order, loading }) => ({
    loading: loading.effects['order/fakeCheckOrder'],
}))(CheckOrderForm);
;
